package com.example.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bean.blockchainCompanyInfo;
import com.example.bean.query.BlockchainApplicationQuery;
import com.example.bean.query.UserQuery;
import com.example.bean.sysUser;
import com.example.common.BaseContext;
import com.example.common.InvokeResult;
import com.example.service.BlockchainCompanyInfoService;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("stage-api")
public class EmUserController {

    @Autowired
    BlockchainCompanyInfoService blockchainCompanyInfoService;



    @Autowired
    UserService userService;




    @PostMapping("/admin/users/list")
    public InvokeResult list(@RequestBody UserQuery query){

        Page<sysUser> pg = new Page<sysUser>(1, query.getPageSize());

        LambdaQueryWrapper<sysUser> wrapper = new LambdaQueryWrapper<sysUser>();

        wrapper.like(query.getUsername()!=null,sysUser::getUsername,query.getUsername());
        wrapper.like(query.getEmail()!=null,sysUser::getEmail,query.getEmail());

        userService.page(pg,wrapper);

        List<UserQuery> list = new ArrayList<>();

        for (sysUser user : pg.getRecords()) {
            UserQuery q = new UserQuery();
            q.setUsername(user.getUsername());
            q.setName(user.getName());
            q.setEmail(user.getEmail());
            q.setMobile(user.getMobile());
            q.setCreatedDate(user.getCreatedDate().toString());
            q.setRole(user.getRole());
            q.setAuditStatus(user.getAuditStatus());

            list.add(q);
        }

        return InvokeResult.success(list);


    }


    @PostMapping("/admin/users/delete")
    public InvokeResult delete(Integer id) {

        System.out.println(id);
        userService.removeById(id);

        return InvokeResult.success("0","删除成功！");
    }


    @PostMapping("/admin/users/detail")
    public InvokeResult detail(Long id) {

        sysUser user = userService.getById(id);

        UserQuery q = new UserQuery();

        q.setUsername("111111");
        q.setName("221111");
        q.setEmail("331111@qq.com");
        q.setMobile("1111");
        q.setCreatedDate("user.getCreatedDate().toString()");
        q.setRole("user.getRole()");
        q.setAuditStatus(1);


        return InvokeResult.success(q);
    }


}
